#include <iostream>
#include <iterator>
#include <fstream>
#include <algorithm>
#include <list>
#include <deque>
#include <set>
#include <sstream>
#include <map>
using namespace std;
int main(int argc, char **argv)
{
    std::ifstream in(argv[1]);
    if (!in)
    {
        std::cerr << "no file" << std::endl;
        return -1;
    }
    map<string, set<int>> word_lines;
    string line;
    string word;
    int line_no = 0;
    while (getline(in, line))
    {
        ++line_no;
        istringstream record(line);
        while (record >> word)
        {
            word_lines[word].insert(line_no);
        }
    }

    for (const auto &w : word_lines)
    {
        cout << '`' << w.first << '`' << " occurs on lines: ";
        for (auto n : w.second)
        {
            cout << n << " ";
        }
        cout << endl;
    }
}
